/*
Class: pathfinder
This class is used to receive a sequence of positions (float3) that avoid the obstacles (std::vector<Polygon>)
and reach the destination (float3).

Future features:
Object bounding sphere for more realistic approximation,

Bugs:
Object will still follow the initial shortest path even
if it has to go around a longer perimeter.
*/


#pragma once
#include "Polygon.h"
#include "PolygonView.h"
#include "PolyLine.h"
#include "PolyLineView.h"
#include "Collision.h"

namespace poly
{
	class pathfinder
	{

	public:
		pathfinder();

		/**
		* @param float3: Center of the moving object.
		* @param float3: Destination of the moving object.
		* @param std::vector<Polygon> : Vector of Polygon type obstacles.
		*/
		void begin(float3 object, float3 destination, std::vector<Polygon> obstacle);
		/**
		* @return float3: Next best path calculated from the moving
		* object's current point that it is moving to.
		* Used for step-by-step pathfinding.
		*/
		float3 next();
		/**
		* @return float3: Next best path calculated from the moving
		* object's current position.
		* Used for frame-by-frame pathfinding.
		*/
		float3 next(float3 objectPosition);

		/**
		* @return bool: True if destination is visible given the
		* object's current position. Should be used for optimization
		* by ending the pathfinding if destination is visible during
		* the object's movement
		* @param float3: Object's current position.
		*/
		bool destinationVisible(float3 objectPosition);

		/**
		* Clears up the system. Must be called whenever
		* pathfinding is done.
		*/
		void end();

	private:
		/**
		* Main algorithm.
		*/
		float3 find();

	private:
		/**
		 * Set of obstacles.
		 */
		std::vector<Polygon> m_ObstacleVector;

		/**
		 * Center of the moving object.
		 */
		float3				 m_ObjectCenter;
		/**
		 * Final destination of the object.
		 */
		float3				 m_ObjectDestination;
		/**
		 * Current destination of the object. 
		 */
		float3				 m_ObjectMoveTo;

		/**
		 * Line from Destination to the Object.
		 */
		PolyLine			 m_LineDestObject;
	};
}